package com.semidata.trp.business.http;

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.HttpRequest;

import com.semidata.rtd.core.http.server.AbstractDispatchHandler;
import com.semidata.rtd.core.http.server.HttpSession;
import com.semidata.rtd.core.service.ServiceManager;
import com.semidata.trp.business.report.MonitorReportData;
import com.semidata.trp.business.report.ReportService;

public class MonitorReportHttpHandler extends AbstractDispatchHandler {

    public MonitorReportHttpHandler(ChannelHandlerContext ctx, HttpRequest request) {
        super(ctx, request);
    }

    @Override
    public void handle(HttpSession session) {
        try {
            byte[] bytes = new byte[session.getBuffer().writerIndex()];
            session.getBuffer().getBytes(0, bytes);
            MonitorReportData data = new MonitorReportData(bytes);
            ServiceManager.getService(ReportService.class).send(data);
            session.getResponse().end();
        } catch (Exception e) {
            session.getResponse().error();
        }
    }

}
